<%@ page language="java" pageEncoding="UTF-8"%><%@ taglib prefix="aurorapt" uri="http://java.aurora.com/aurora/permission"%>
<!DOCTYPE html>
<html>
<head>
<title>商家管理</title>
<meta name="content-type" content="text/html; charset=UTF-8">
<jsp:include page="/pub.jsp"></jsp:include>
<script type="text/javascript">
var aotemaiShopDataGrid;
$(function() {
	aotemaiShopDataGrid = $('#aotemaiShop_datagrid').datagrid({
		url : '${pageContext.request.contextPath}/aotemaiShop/list',
		fit : true,
		fitColumns : true,
		border : false,
		pagination : true,
		idField : 'id',
		pagePosition : 'both',
		checkOnSelect:true,
		selectOnCheck:true,
		columns : [ [ {
			field : 'id',
			title : '编号',
			width : 100,
			checkbox : true
		}, {
			field : 'ID',
			title : '商家ID',
			width : 60,
        	formatter: function(value,row,index){
        		return '<span style="color:blue">'+ row.id +'</span>';
			}
		}, {
			field : 'no',
			title : '编号',
			width : 50
		}, {
			field : 'name',
			title : '商家名',
			width : 120
		}, {
			field : 'address',
			title : '地址',
			width : 200
		}, {
			field : 'email',
			title : '邮箱',
			width : 120
		}, {
			field : 'mobile',
			title : '手机/座机号',
			width : 100
		}, {
			field : 'member',
			title : '绑定会员号',
			width : 100
		},
		{field : 'thumbnail',title : '缩略图',width : 60,
			formatter: function(value,row,index){
				return '<img onclick="javascript:window.open(this.src)" style="cursor:hand" width="60px" height="60px" border="0" src="${pageContext.request.contextPath}'+value+'"/>';
			}
		}, {
			field : 'remark',
			title : '备注',
			width : 100
		}] ],
		onLoadSuccess:function(){
            $(this).datagrid('doCellTip',{'max-width':'300px','delay':500});
        },
		onRowContextMenu:function(e, rowIndex, rowData){
			e.preventDefault();
			$(this).datagrid('clearSelections');
			$(this).datagrid('clearChecked');
			$(this).datagrid('selectRow',rowIndex);
			$('#aotemaiShop_menu').menu('show', {
				left : e.pageX,
				top : e.pageY
			});
		},toolbar:'#tb'
	});
	
});

function aotemaiShopAdd() {
	var dialog = parent.modalDialog({
		title : '商家添加',
		width : 600,
		height : 600,
		url : '${pageContext.request.contextPath}/aotemaiShop/addUI',
		buttons : [ {
			text : '添加',
			handler : function() {
				dialog.find('iframe').get(0).contentWindow.aotemaiShop_add_submitForm(dialog, aotemaiShopDataGrid, parent.$);
			}
		} ]
	});
}

function aotemaiShopEdit(){
	var rows = aotemaiShopDataGrid.datagrid('getChecked');
	if(rows.length==1){
		var dialog = parent.modalDialog({
			title : '商家编辑',
			width : 600,
			height : 600,
			url : '${pageContext.request.contextPath}/aotemaiShop/editUI/'+rows[0].id,
			buttons : [ {
				text : '编辑',
				handler : function() {
					dialog.find('iframe').get(0).contentWindow.aotemaiShop_edit_submitForm(dialog, aotemaiShopDataGrid, parent.$);
				}
			} ]
		});
	}else{
		parent.$.messager.alert('提示','请选择一条记录进行操作');
	}
}
function aotemaiShopDelete(){
	var rows = aotemaiShopDataGrid.datagrid('getChecked');
	if(rows.length==1){
		$.messager.confirm('确认','您确认想要删除记录吗？',function(r){
		    if (r){
				$.post('${pageContext.request.contextPath}/aotemaiShop/delete/'+rows[0].id, function(j) {
					if (j.success) {
						aotemaiShopDataGrid.datagrid('reload');
					}
					aotemaiShopDataGrid.datagrid('uncheckAll');
					$.messager.show({
						title : '提示',
						msg : j.msg,
						timeout : 5000,
						showType : 'slide'
					});
				}, 'json').error(function() {
					$.messager.show({
						title : '提示',
						msg : '你的权限不够',
						timeout : 5000,
						showType : 'slide'
					});
				});
		    }    
		});
	}else{
		parent.$.messager.alert('提示','请选择一条记录进行操作');
	}
}
/* ------------------------------拓展功能 --------------------- */
/* 添加所料图片 */
function shopPictureAddThumbnail(){
	var rows = aotemaiShopDataGrid.datagrid('getChecked');
	if(rows.length==1){
		var dialog = parent.modalDialog({
			title : '缩略图编辑',
			width : 600,
			height : 400,
			url : '${pageContext.request.contextPath}/aotemaiShop/addShopThumbnailPictureUI/'+rows[0].id
		});
	}else{
		parent.$.messager.alert('提示','请选择一条记录后，再操作');
	}
}
/* 添加展示图片 */
function shopPictureAdd(){
	var rows = aotemaiShopDataGrid.datagrid('getChecked');
	if(rows.length==1){
		var dialog = parent.modalDialog({
			title : '添加展示图片',
			width : 800,
			height : 420,
			url : '${pageContext.request.contextPath}/aotemaiShop/addShopPictureUI/'+rows[0].id
		});
	}else{
		parent.$.messager.alert('提示','请选择一条记录后，再操作');
	}
}
/* 绑定会员 */
function bindAccount(){
	var rows = aotemaiShopDataGrid.datagrid('getChecked');
	if(rows.length==1){
		var dialog = parent.modalDialog({
			title : '绑定会员',
			width : 400,
			height : 300,
			url : '${pageContext.request.contextPath}/aotemaiShop/bindAccountUI/'+rows[0].id,
			buttons : [ {
				text : '确认绑定',
				handler : function() {
					dialog.find('iframe').get(0).contentWindow.aotemaiShop_bindAccount_submitForm(dialog, aotemaiShopDataGrid, parent.$);
				}
			} ]
		});
	}else{
		parent.$.messager.alert('提示','请选择一条记录后，再操作');
	}
}
function aotemaiShop_searchFun() {
	$('#aotemaiShop_datagrid').datagrid('load', serializeObject($('#aotemaiShop_searchForm')));
}
function aotemaiShop_clearFun() {
	$('#aotemaiShop_searchForm input').val('');
}
</script>
</head>

<body>
<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',border:false,title:'商家列表'" style="overflow: hidden;">
		<table id="aotemaiShop_datagrid"></table>
	</div>
</div>

<div id="tb" style="padding:2px 5px;">
	<form id="aotemaiShop_searchForm">
		<aurorapt:permission privilege="shop_addUI">
		<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="ext-icon-add" onclick="aotemaiShopAdd();">添加</a></aurorapt:permission>
		<aurorapt:permission privilege="shop_editUI">
		<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="ext-icon-pencil" onclick="aotemaiShopEdit();">修改</a></aurorapt:permission>
		<aurorapt:permission privilege="shop_delete">
		<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-no" onclick="aotemaiShopDelete();">删除</a></aurorapt:permission>
		<aurorapt:permission privilege="shop_addShopThumbnailPictureUI">
		<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="ext-icon-pencil" onclick="shopPictureAddThumbnail();">缩略图编辑</a></aurorapt:permission>
		<aurorapt:permission privilege="shop_addShopPictureUI">
		<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-add" onclick="shopPictureAdd();">添加展示图</a></aurorapt:permission>
		<aurorapt:permission privilege="shop_bindAccountUI">
		<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="ext-icon-link" onclick="bindAccount();">绑定会员</a></aurorapt:permission>
		商家名：<input class="easyui-textbox" name="name"/>
		编号：<input class="easyui-textbox" name="no"/>
        <a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-search" onclick="aotemaiShop_searchFun();">查询</a>
        <a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-clear" onclick="aotemaiShop_clearFun();">清空</a>
	</form>
</div>

<div id="aotemaiShop_menu" class="easyui-menu" style="width: 120px;display: none;">
	<aurorapt:permission privilege="shop_addUI">
	<div onclick="aotemaiShopAdd()" iconCls="icon-add">增加</div></aurorapt:permission>
	<aurorapt:permission privilege="shop_editUI">
	<div onclick="aotemaiShopEdit()" iconCls="icon-edit">编辑</div></aurorapt:permission>
	<aurorapt:permission privilege="shop_delete">
	<div onclick="aotemaiShopDelete()" iconCls="icon-no">删除</div></aurorapt:permission>
	<aurorapt:permission privilege="shop_addShopThumbnailPictureUI">
	<div onclick="shopPictureAddThumbnail()" iconCls="ext-icon-pencil">缩略图编辑</div></aurorapt:permission>
	<aurorapt:permission privilege="shop_addShopPictureUI">
	<div onclick="shopPictureAdd()" iconCls="icon-add">添加展示图片</div></aurorapt:permission>
	<aurorapt:permission privilege="shop_bindAccountUI">
	<div onclick="bindAccount()" iconCls="ext-icon-link">绑定会员</div></aurorapt:permission>
</div>
</body>
</html>